﻿Imports FinanceiroBLL
Imports FinanceiroDAL
Public Class ContasLançamentosFRM
    Dim valorparcela As Decimal
    Dim objCre As New ContasReceberBLL
    Public var As Integer
    Dim codcusto, codigo As Integer
#Region "Localizar"
    Private Sub BLocaliza_Click(sender As System.Object, e As System.EventArgs) Handles BLocaliza.Click
        Dim frmcc As New PlanodeContasCON
        frmcc.tipo = "Entrada"
        frmcc.ShowDialog()
        TXTConta.Text = frmcc.ccusto
        codcusto = frmcc.ccccod
        frmcc.Dispose()
        frmcc = Nothing
    End Sub
#End Region
#Region "salvar"
    Private Sub TSBSalvar_Click(sender As System.Object, e As System.EventArgs) Handles TSBSalvar.Click
        Try
            Dim valor As Decimal
            Decimal.TryParse(TXTValorParcela.Text.Replace("R$", ""), valor)

            objCre = New ContasReceberBLL(codigo, 0, codcusto, Date.Parse(DTPEmissao.Text), 0, valor) 'Entra Dinheiro -Receber
            Dim objitrecBLL As New itensCtasReceberBLL
            objitrecBLL.icrdtrecebimento = DTPLancamento.Value 'ou txt
            objitrecBLL.icrvalor = valor
            objitrecBLL.pagcodigo = CBFaturamento.SelectedValue
            objitrecBLL.icrdtvencimento = DTPLancamento.Value
            objitrecBLL.icrvalrecebido = valor 'campo total + jam -desc
            objitrecBLL.icrdesconto = 0
            objitrecBLL.icrjam = 0
            objitrecBLL.icrparcela = 1 'num de parcela
            objitrecBLL.icrobs = "Lançamentos de Entrada "
            objitrecBLL.concodigo = CBContas.SelectedValue
            objitrecBLL.icrbolcheque = TXTBolCheque.Text
            objitrecBLL.stacodigo = 6
            objCre.lCtasreceber.Add(objitrecBLL)
            var = objCre.Inserir()
            var = objCre.ctrcodigo
            MessageBox.Show("Conta inserida com sucesso!", "Sucesso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        Catch ex As Exception
            Throw New Exception("Erro durante a inclusão")
        End Try
       
    End Sub
#End Region
#Region "Load"
    Private Sub ContasLançamentosFRM_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        limpar()
        inicializacombo()
    End Sub
#End Region
#Region "Limpar"
    Sub limpar()
        TXTBolCheque.Text = ""
        TXTConta.Text = ""
        TXTNumref.Text = ""
        TXTObservacao.Text = ""
        TXTValorParcela.Text = ""
        '   ObjBLL.limpar()
    End Sub
#End Region
#Region "inicializa combo"
    Sub inicializacombo()
        objconexao.carregaCombo(CBFaturamento, "Generico.Gen_FormaPagamento", "pag_codigo", "pag_descricao", "sta_codigo =1", "")
        objconexao.carregaCombo(CBContas, "Financeiro.Ofi_Contas", "con_codigo", "con_descricao", "sta_codigo=1", "")
        CBContas.SelectedValue = -1
        CBFaturamento.SelectedValue = -1
    End Sub
#End Region
#Region "Voltar"
    Private Sub TSBVoltar_Click(sender As System.Object, e As System.EventArgs) Handles TSBVoltar.Click
        Me.Close()
        limpar()
        objCre = Nothing
    End Sub
#End Region
#Region "KeyPress"
    Private Sub TXTValorParcela_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs)
        If Not Char.IsNumber(e.KeyChar) And Not e.KeyChar = vbBack And Not e.KeyChar = "." And Not e.KeyChar = "," Then
            e.Handled = True
        End If
        If e.KeyChar = Convert.ToChar(Keys.Return) Then
        End If

    End Sub
#End Region
#Region "KeyPress FRM"
    Private Sub ContasLançamentosFRM_KeyPress(sender As System.Object, e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.KeyPress
        If e.KeyChar = Convert.ToChar(13) Then
            e.Handled = True
            SendKeys.Send("{TAB}")
        End If
    End Sub
#End Region

#Region "ValidaCampos"
    Sub validacampos()
        Try
            If (TXTValorParcela.Text <> "") Then
                TXTValorParcela.Text = FormatCurrency(TXTValorParcela.Text)
            Else : TXTValorParcela.Text = "0,00"
            End If
            TXTValorParcela.Text = FormatCurrency(TXTValorParcela.Text)
        Catch ex As Exception
            '    MsgBox("Formato incorreto nos campos!")
        End Try
    End Sub
#End Region
    Private Sub TXTValorParcela_Leave(sender As System.Object, e As System.EventArgs) Handles TXTValorParcela.Leave
        validacampos()
    End Sub

    Private Sub TXTValorParcela_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles TXTValorParcela.Validating
        validacampos()
    End Sub
End Class